package main

import (
	"github.com/go-redis/redis"
	"time"
)

// redis
const (
	CacheDB = iota
	CacheLog
	CacheWatch
)

var CacheDBClient *redis.Client // 操作登录缓存信息
var CacheWatchClient *redis.Client

func Init() {
	// 初始化 CacheLogin
	CacheDBClient = redis.NewClient(&redis.Options{
		Addr:            "localhost:6379",
		Password:        "",
		DB:              CacheDB,
		MaxRetries:      1,
		MaxRetryBackoff: 10 * time.Second,
	})
	_, err := CacheDBClient.Ping().Result()
	if err != nil {
		panic(err.Error())
	}
	// 初始化 CacheApi
	CacheWatchClient = redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "",
		DB:       CacheWatch,
	})
	_, err = CacheWatchClient.Ping().Result()
	if err != nil {
		panic(err.Error())
	}
	return
}
